<template>
  <div class="home">
    <!-- 3D 轮播图部分 -->
    <div class="banner-wrapper">
      <div class="banner-carousel" 
           @mouseenter="pauseAutoPlay"
           @mouseleave="startAutoPlay">
        <div class="carousel-3d-container" 
             :style="{ transform: `translateZ(-${translateZ}px) rotateY(${currentRotation}deg)` }">
          <div v-for="(slide, index) in bannerSlides" 
               :key="index"
               class="carousel-slide"
               :style="getSlideStyle(index)"
               @click="goToSlide(index)">
            <div class="slide-content">
              <img :src="slide.image" :alt="slide.title">
              <div class="slide-info">
                <h2>{{ slide.title }}</h2>
                <p>{{ slide.description }}</p>
                <button class="slide-btn">
                  <i class="iconfont icon-play1"></i>
                  立即播放
                </button>
              </div>
              <div class="slide-overlay"></div>
            </div>
          </div>
        </div>

        <!-- 控制按钮 -->
        <div class="carousel-controls">
          <button class="control-btn prev" @click="prevSlide">
            <i class="iconfont icon-prev"></i>
          </button>
          <div class="carousel-indicators">
            <span v-for="(_, index) in bannerSlides" 
                  :key="index"
                  :class="['indicator-dot', { active: currentSlide === index }]"
                  @click="goToSlide(index)">
            </span>
          </div>
          <button class="control-btn next" @click="nextSlide">
            <i class="iconfont icon-next"></i>
          </button>
        </div>
      </div>
    </div>

    <!-- 快捷入口 -->
    <div class="quick-access-wrapper">
      <div class="quick-access">
        <div v-for="(item, index) in quickAccess" :key="index" class="quick-item">
          <i :class="item.icon"></i>
          <span>{{ item.name }}</span>
        </div>
      </div>
    </div>

    <!-- 推荐歌单 -->
    <section class="section playlist-section">
      <div class="section-header">
        <h2 class="section-title">推荐歌单</h2>
        <router-link to="/playlist" class="more-link">
          更多 <i class="iconfont icon-arrow-right"></i>
        </router-link>
      </div>
      <div class="playlist-grid">
        <div v-for="(playlist, index) in recommendPlaylists" 
             :key="playlist.id" 
             class="playlist-card"
             :style="{ animationDelay: `${index * 0.1}s` }">
          <div class="playlist-cover">
            <img :src="playlist.cover" :alt="playlist.name">
            <div class="play-hover">
              <div class="play-btn">
                <i class="iconfont icon-play1"></i>
              </div>
            </div>
            <div class="playlist-info">
              <span class="play-count">
                <i class="iconfont icon-play1"></i>
                {{ formatCount(playlist.playCount) }}
              </span>
              <span class="playlist-type">{{ playlist.type }}</span>
            </div>
          </div>
          <div class="playlist-content">
            <h3 class="playlist-title">{{ playlist.name }}</h3>
            <p class="playlist-desc">{{ playlist.description }}</p>
          </div>
        </div>
      </div>
    </section>

    <!-- 最新音乐 -->
    <section class="section">
      <div class="section-header">
        <h2 class="section-title">最新音乐</h2>
        <a href="#" class="more-link">更多 <i class="iconfont icon-arrow-right"></i></a>
      </div>
      <div class="latest-music">
        <div v-for="song in latestSongs" :key="song.id" class="song-item">
          <img :src="song.cover" :alt="song.name" class="song-cover">
          <div class="song-info">
            <h3 class="song-name">{{ song.name }}</h3>
            <p class="song-artist">{{ song.artist }}</p>
          </div>
          <div class="song-actions">
            <i class="iconfont icon-play1"></i>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      currentSlide: 0,
      autoPlayTimer: null,
      translateZ: 400, // 3D 深度
      bannerSlides: [
        {
          image: 'https://picsum.photos/1200/400?random=1',
          title: '2024流行音乐盛典',
          description: '聆听年度最佳音乐'
        },
        {
          image: 'https://picsum.photos/1200/400?random=2',
          title: '经典怀旧金曲',
          description: '重温永恒经典'
        },
        {
          image: 'https://picsum.photos/1200/400?random=3',
          title: '独立音乐专场',
          description: '发现原创好音乐'
        },
        {
          image: 'https://picsum.photos/1200/400?random=4',
          title: '电音派对',
          description: '点燃你的夜晚'
        }
      ],
      quickAccess: [
        { name: '每日推荐', icon: 'iconfont icon-calendar' },
        { name: '私人FM', icon: 'iconfont icon-radio' },
        { name: '排行榜', icon: 'iconfont icon-rank' },
        { name: '直播', icon: 'iconfont icon-live' }
      ],
      recommendPlaylists: [
        {
          id: 1,
          name: '【流行】2024最热新歌',
          description: '精选最热门的流行音乐',
          cover: 'https://picsum.photos/300/300?random=1',
          playCount: 1234567,
          type: '官方歌单'
        },
        {
          id: 2,
          name: '治愈系民谣精选',
          description: '温暖你的每一天',
          cover: 'https://picsum.photos/300/300?random=2',
          playCount: 890123,
          type: '精品歌单'
        },
        {
          id: 3,
          name: '经典摇滚回顾',
          description: '重温经典摇滚时刻',
          cover: 'https://picsum.photos/300/300?random=3',
          playCount: 567890,
          type: '摇滚专区'
        },
        {
          id: 4,
          name: '电音派对必备',
          description: '点燃你的派对时刻',
          cover: 'https://picsum.photos/300/300?random=4',
          playCount: 345678,
          type: '电音专区'
        }
      ],
      latestSongs: [
        {
          id: 1,
          name: '新歌1',
          artist: '歌手1',
          cover: 'https://picsum.photos/100/100?random=1'
        },
        {
          id: 2,
          name: '新歌2',
          artist: '歌手2',
          cover: 'https://picsum.photos/100/100?random=2'
        },
        {
          id: 3,
          name: '新歌3',
          artist: '歌手3',
          cover: 'https://picsum.photos/100/100?random=3'
        }
      ]
    }
  },
  computed: {
    currentRotation() {
      return -(360 / this.bannerSlides.length) * this.currentSlide
    }
  },
  methods: {
    getSlideStyle(index) {
      const angle = (360 / this.bannerSlides.length) * index
      return {
        transform: `rotateY(${angle}deg) translateZ(${this.translateZ}px)`
      }
    },
    goToSlide(index) {
      this.currentSlide = index
    },
    nextSlide() {
      this.currentSlide = (this.currentSlide + 1) % this.bannerSlides.length
    },
    prevSlide() {
      this.currentSlide = this.currentSlide === 0 
        ? this.bannerSlides.length - 1 
        : this.currentSlide - 1
    },
    startAutoPlay() {
      this.autoPlayTimer = setInterval(this.nextSlide, 5000)
    },
    pauseAutoPlay() {
      clearInterval(this.autoPlayTimer)
    },
    formatCount(count) {
      if (count >= 10000) {
        return (count / 10000).toFixed(1) + '万'
      }
      return count
    }
  },
  mounted() {
    this.startAutoPlay()
  },
  beforeDestroy() {
    clearInterval(this.autoPlayTimer)
  }
}
</script>

<style scoped>
.home {
  padding-bottom: 40px;
}

/* 3D 轮播图样式 */
.banner-wrapper {
  padding: 40px 20px;
  perspective: 1200px;
  background: linear-gradient(to bottom, #f8f9fa, transparent);
}

.banner-carousel {
  position: relative;
  width: 100%;
  height: 400px;
  margin: 0 auto;
  max-width: 1200px;
}

.carousel-3d-container {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.carousel-slide {
  position: absolute;
  width: 60%;
  height: 100%;
  left: 20%;
  top: 0;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.slide-content {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0,0,0,0.2);
  transform: scale(0.95);
  transition: all 0.4s ease;
}

.carousel-slide:hover .slide-content {
  transform: scale(1);
}

.slide-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.carousel-slide:hover img {
  transform: scale(1.05);
}

.slide-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px;
  color: white;
  z-index: 2;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.4s ease;
}

.carousel-slide:hover .slide-info {
  transform: translateY(0);
  opacity: 1;
}

.slide-info h2 {
  font-size: 2em;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.slide-info p {
  font-size: 1.1em;
  margin-bottom: 20px;
  opacity: 0.9;
}

.slide-btn {
  padding: 12px 25px;
  border: none;
  background: #ff6b6b;
  color: white;
  border-radius: 25px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.slide-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}

.slide-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.carousel-slide:hover .slide-overlay {
  opacity: 1;
}

/* 控制按钮样式 */
.carousel-controls {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 20px;
  z-index: 10;
}

.control-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #ff6b6b;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn:hover {
  background: #ff6b6b;
  color: white;
  transform: scale(1.1);
}

.carousel-indicators {
  display: flex;
  gap: 10px;
}

.indicator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 0.3s ease;
}

.indicator-dot.active {
  background: white;
  transform: scale(1.2);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .banner-wrapper {
    padding: 20px 10px;
  }

  .banner-carousel {
    height: 300px;
  }

  .carousel-slide {
    width: 80%;
    left: 10%;
  }

  .slide-info h2 {
    font-size: 1.5em;
  }

  .slide-info p {
    font-size: 1em;
  }

  .control-btn {
    width: 36px;
    height: 36px;
  }
}

/* 快捷入口样式 */
.quick-access-wrapper {
  padding: 0 20px;
  margin-top: 30px;
  margin-bottom: 30px;
}

.quick-access {
  display: flex;
  justify-content: space-around;
  padding: 25px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.1);
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 15px 25px;
  border-radius: 12px;
}

.quick-item:hover {
  transform: translateY(-5px);
  background: rgba(255, 107, 107, 0.1);
}

.quick-item i {
  font-size: 28px;
  color: #ff6b6b;
  transition: all 0.3s ease;
}

.quick-item:hover i {
  transform: scale(1.2);
  color: #ff4757;
}

.quick-item span {
  font-size: 15px;
  font-weight: 500;
  color: #444;
  transition: color 0.3s ease;
}

.quick-item:hover span {
  color: #ff6b6b;
}

/* 区块通用样式 */
.section {
  margin-bottom: 40px;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  font-size: 24px;
  position: relative;
  padding-left: 15px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 20px;
  background: #ff6b6b;
  border-radius: 2px;
}

.more-link {
  color: #666;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.3s ease;
}

.more-link:hover {
  color: #ff6b6b;
}

/* 最新音乐样式 */
.latest-music {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.song-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.song-item:hover {
  background: #f5f5f5;
}

.song-cover {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  margin-right: 15px;
}

.song-info {
  flex: 1;
}

.song-name {
  font-size: 16px;
  margin-bottom: 5px;
}

.song-artist {
  font-size: 14px;
  color: #666;
}

.song-actions {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.song-item:hover .song-actions {
  opacity: 1;
}

.song-actions i {
  font-size: 24px;
  color: #ff6b6b;
  cursor: pointer;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .banner-wrapper {
    padding: 10px;
    margin-top: 10px;
  }

  .banner-carousel {
    height: 200px;
    border-radius: 12px;
  }

  .quick-access {
    padding: 15px;
    flex-wrap: wrap;
  }

  .quick-item {
    padding: 10px 15px;
  }

  .slide-content {
    padding: 40px 20px 20px;
  }

  .slide-content h2 {
    font-size: 1.5em;
  }

  .slide-content p {
    font-size: 1em;
  }

  .latest-music {
    grid-template-columns: 1fr;
  }
}

.playlist-section {
  position: relative;
  overflow: hidden;
}

.playlist-section::before {
  content: '';
  position: absolute;
  top: -100px;
  right: -100px;
  width: 200px;
  height: 200px;
  background: linear-gradient(45deg, #ff9a9e, #fad0c4);
  border-radius: 50%;
  opacity: 0.1;
  z-index: 0;
}

.playlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 25px;
  padding: 10px;
}

.playlist-card {
  background: white;
  border-radius: 15px;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  animation: slideUp 0.6s ease-out forwards;
  opacity: 0;
  transform: translateY(30px);
}

@keyframes slideUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.playlist-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 8px 20px rgba(255, 107, 107, 0.2);
}

.playlist-cover {
  position: relative;
  padding-top: 100%;
  overflow: hidden;
}

.playlist-cover img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s ease;
}

.playlist-card:hover .playlist-cover img {
  transform: scale(1.1);
}

.play-hover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.3s ease;
}

.play-btn {
  width: 60px;
  height: 60px;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.8);
  transition: all 0.3s ease;
}

.play-btn i {
  font-size: 30px;
  color: #ff6b6b;
  margin-left: 5px;
}

.playlist-card:hover .play-hover {
  opacity: 1;
}

.playlist-card:hover .play-btn {
  transform: scale(1);
}

.playlist-info {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  color: white;
  font-size: 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent);
}

.play-count {
  background: rgba(0,0,0,0.5);
  padding: 4px 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.playlist-type {
  background: #ff6b6b;
  padding: 4px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.playlist-content {
  padding: 15px;
}

.playlist-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.playlist-desc {
  font-size: 13px;
  color: #666;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .playlist-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
  }
  
  .play-btn {
    width: 50px;
    height: 50px;
  }
  
  .play-btn i {
    font-size: 24px;
  }
  
  .playlist-title {
    font-size: 14px;
  }
  
  .playlist-desc {
    font-size: 12px;
  }
}
</style> 